from django.db import models

class Type(models.Model):
    name = models.CharField(max_length=200)
    def __unicode__(self):
        return '<Type "%s">' % self.name

class Subtype(models.Model):
    name = models.CharField(max_length=200)
    def __unicode__(self):
        return '<Subtype "%s">' % self.name

class Color(models.Model):
    name = models.CharField(max_length=200)
    cost_char = models.CharField(max_length=1)
    def __unicode__(self):
        return '<Color "%s">' % self.name

class Set(models.Model):
    name = models.CharField(max_length=200)
    def __unicode__(self):
        return '<Set "%s">' % self.name

class Tag(models.Model):
    name = models.CharField(max_length=500)
    def __unicode__(self):
        return '<Tag "%s">' % self.name

class Card(models.Model):
    name = models.CharField(max_length=200)
    cost = models.CharField(max_length=50)
    rules_text = models.TextField(blank=True)
    flavor_text = models.TextField(blank=True)
    power = models.IntegerField(blank=True, null=True)
    toughness = models.IntegerField(blank=True, null=True)
    def __unicode__(self):
        return '<Card "%s">' % self.name

class CardType(models.Model):
    card = models.ForeignKey(Card)
    type = models.ForeignKey(Type)
    def __unicode__(self):
        card_name = self.card.name if self.card else 'none'
        type_name = self.type.name if self.type else 'none'
        return '<CardType "%s","%s">' % (card_name, type_name)

class CardSubtype(models.Model):
    card = models.ForeignKey(Card)
    subtype = models.ForeignKey(Subtype)
    def __unicode__(self):
        card_name = self.card.name if self.card else 'none'
        subtype_name = self.subtype.name if self.subtype else 'none'
        return '<CardSubtype "%s","%s">' % (card_name, subtype_name)

class CardTag(models.Model):
    card = models.ForeignKey(Card)
    tag = models.ForeignKey(Tag)
    def __unicode__(self):
        card_name = self.card.name if self.card else 'none'
        tag_name = self.tag.name if self.tag else 'none'
        return '<CardTag "%s","%s">' % (card_name, tag_name)

class Image(models.Model):
    name = models.CharField(max_length=200)
    def __unicode__(self):
        return '<Image "%s">' % self.name

class CardPrint(models.Model):
    card = models.ForeignKey(Card)
    set = models.ForeignKey(Set)
    image = models.ForeignKey(Image)
    def __unicode__(self):
        card_name = self.card.name if self.card else 'none'
        return '<CardPrint "%s">' % card_name

